package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.nursing.domain.DeviceData;
import com.zzyl.nursing.domain.FamilyMember;
import com.zzyl.nursing.dto.BindingFamilyDto;
import com.zzyl.nursing.dto.QueryDeviceDataListDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.vo.FamilyByPageVo;
import com.zzyl.nursing.vo.FamilyMemberVo;
import com.zzyl.nursing.vo.LoginVo;
import com.zzyl.nursing.vo.QueryDeviceDataListVo;
import com.zzyl.nursing.vo.health.HealthDataVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 老人家属Controller
 *
 * @author ruoyi
 * @date 2025-04-26
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属的接口")
public class FamilyMemberController extends BaseController {
    @Autowired
    private IFamilyMemberService familyMemberService;

    @PostMapping("/login")
    public AjaxResult login(@RequestBody UserLoginRequestDto dto) {
        LoginVo vo = familyMemberService.login(dto);
        return success(vo);
    }

    /**
     * 新增(绑定家人)
     *
     * @param dto 绑定家人信息(小程序端传递的参数)
     * @return 绑定结果
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody BindingFamilyDto dto) {
        familyMemberService.add(dto);
        return success();
    }

    /**
     * 按天统计查询指标数据
     * @return 指标数据
     */
    @GetMapping("/queryDeviceDataListByDay")
    public AjaxResult queryDeviceDataListByDay(QueryDeviceDataListDto dto) {
        List<QueryDeviceDataListVo> list = familyMemberService.queryDeviceDataListByDay(dto);
        return success(list);
    }

    /**
     * 查询家人列表
     *
     * @return 家人列表
     */
    @GetMapping("my")
    public AjaxResult my() {
        List<FamilyMemberVo> list = familyMemberService.my();
        return success(list);
    }

    /**
     * 按周统计查询指标数据
     * @return 指标数据
     */
    @GetMapping("/queryDeviceDataListByWeek")
    public AjaxResult queryDeviceDataListByWeek(QueryDeviceDataListDto dto) {
        List<QueryDeviceDataListVo> list =  familyMemberService.queryDeviceDataListByWeek(dto);
        return success(list);
    }

    /**
     * 查看家人列表（分页查询)
     *
     * @param pageNum  页码
     * @param pageSize 每页数量
     * @return 家人列表
     */
    @GetMapping("/list-by-page")
    public AjaxResult listByPage(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                 @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        startPage();
        List<FamilyByPageVo> list = familyMemberService.listByPage();
        return success(list);
    }

    /**
     * 查询健康数据
     *
     * @param iotId 设备id(路径参数)
     * @return 健康数据
     */
    @GetMapping("/queryServiceProperties/{iotId}")
    public AjaxResult queryServiceProperties(@PathVariable String iotId) {
        List<HealthDataVo> list = familyMemberService.queryServiceProperties(iotId);
        return success(list);
    }
}
